package com.sxt;

import java.awt.*;

public class Bg {

    //关卡数
    static int level = 1;
    //目标得分
    int goal = level*15;

    //积分总分
    static int count = 0;

    //药水数量
    static int waterNum = 3;

    //药水状态,默认False，True表示正在使用
    static boolean waterFlag = false;

    //开始时间
    long startTime;
    //结束时间
    long endTime;
    //药水价格
    int price = (int) (Math.random()*10);
    //是否进入商店 f 不购买
    boolean shop = false;



    //载入图片
    Image bg = Toolkit.getDefaultToolkit().getImage("C:/Users/mmq/IdeaProjects/The Gold Miner/imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("C:/Users/mmq/IdeaProjects/The Gold Miner/imgs/bg1.jpg");
    Image peo = Toolkit.getDefaultToolkit().getImage("C:/Users/mmq/IdeaProjects/The Gold Miner/imgs/peo.png");
    Image water = Toolkit.getDefaultToolkit().getImage("C:/Users/mmq/IdeaProjects/The Gold Miner/imgs/water.png");
    /*Image bg =  Toolkit.getDefaultToolkit().getImage("C:/Users/mmq/IdeaProjects/The Gold Miner/imgs/bg.jpg");
        我只用绝对路径了，相对路径我用不了，大概率是Toolkit.getDefaultToolkit().getImage我有点错误*/

    //绘制
    void painSelf(Graphics g){
        g.drawImage(bg1,0,0,null);
        g.drawImage(bg,0,200,null);
        switch (GameWin.state){
            case 0:
                drawWord(g,80,Color.green,"准备开始",200,400);
                break;
            case 1:
                g.drawImage(peo,310,115,null);//把人物当背景处理了
                drawWord(g,30,Color.black,"积分："+count,30,150);

                //药水组件
                g.drawImage(water,430,75,null);                      //药水照片位置
                drawWord(g,30,Color.black,"*"+waterNum,500,120);     //药水文字位置

                //关卡数
                drawWord(g,20,Color.black,"第"+level+"关",30,60);
                //目标积分
                drawWord(g,30,Color.black,"目标"+ goal,30,110);
                //时间组件
                endTime = System.currentTimeMillis();
                long tim =20-(endTime-startTime)/1000;
                drawWord(g,30,Color.black,"时间"+(tim>0?tim:0),580,130);
                break;
            case 2:       //状态2商店界面
                //药水组件
                g.drawImage(water,300,400,null);                      //药水位置
                drawWord(g,30,Color.black,"药水价格"+price,300,500);
                drawWord(g,30,Color.black,"是否购买",300,550);
                if (shop){                                        //如果买药水
                    count = count-price;                            //则积分数减药水价格
                    waterNum++;                                     //药水数加1
                    shop=false;                                     //释放商店状态，
                    GameWin.state=1;                                //并且进入状态1
                    startTime=System.currentTimeMillis();           //重新计时
                }
                break;
            case 3:
                drawWord(g,80,Color.cyan,"失败",270,350);
                drawWord(g,30,Color.cyan,"积分"+ count,310,450);
                break;
            case 4:
                drawWord(g,80,Color.red,"成功",270,350);
                drawWord(g,30,Color.red,"积分"+ count,310,450);
                break;
            default:
        }


    }

    //倒计时完成 false正在倒计时
    boolean gameTime(){
        long tim = (endTime-startTime)/1000;
        if(tim>20) {return true;}
        return false;
    }

    //绘制字符串
    public static void drawWord(Graphics g,int size,Color color,String str,int x,int y){
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(str,x,y);
    }

    /*重置元素*/
     void reGame() {
         //关卡数
         level = 1;
         //目标得分
          goal = level*15;
         //积分总分
           count = 0;
         //药水数量
           waterNum = 3;
         //药水状态,默认False，True表示正在使用
          waterFlag = false;

    }
}
